%*************************************************************************************
%     FileName        : channel.m
%     Author          : Yao Gang
%     Date            : 2003.12.20
%     Version         : 1.0
%     E-mail          : Y.Gang@ed.ac.uk
%     Company         : SLI Group Of University Of Edinburgh
%     Description     : Matalab Code Of Gaussian Noise Channel
%
%                    ! ! !
%                   / o o \
%                  {   >   }
%                   \  ~  /                  <-nobond:yaogang-self_portrait
%                  __|   |__
%***************************************************************************************

%***************************************************************************************
%BPSK BINARY SYMMETRIC CHANNEL SIMULATOR
%***************************************************************************************

function channelsignals = channel(encodedbits,es_over_n0,outputbits);

%encodebits: bitstreams of channel 
%es_over_n0: energy ration of signal/noise ratio 
%outputbits: noise disruppted noise

%***************************************************************************************
%Given that the desired Es/No (for BPSK = Eb/N0 -3db), calculate the standard deviaton of 
%the additive
%white gaussian noise. 
%***************************************************************************************

mean 	    = 0 ;
es   	    = 1 ;
sn_ratio    = pow(10,(es_ovr_n0 / 10));
sigma	    = sqrt( es / ( 2 * sn_ratio));
[length,T]  = size (outputbits);

%***************************************************************************************
%Transform Data from 0/1 to +1/-1 and add noise
%***************************************************************************************
signal = 1-2*encodedbits;
for k = 1 : length 
	noise = gngauss(mean,sigma);
end

outputbits = signal + noise; 

